import config from '@/config.js'
import {
	Encrypt,
	Decrypt
} from '@/js_sdk/cainiao-crypto/cainiao-crypto.js'
export function uploadFile(filePath) {
	return new Promise((resolve, reject) => {
		uni.uploadFile({
			url: config.requestUrl + '/upload',
			filePath,
			header: {
				"Content-Type": "multipart/form-data"
			},
			name: 'file',
			success: (res) => {
				//本地调试时，可以删除此方法
				// if (res.data) {
				// 	const dataJson = JSON.parse(res.data)
				// 	let deStr;
				// 	const mi = Decrypt(dataJson.data);
				// 	try {
				// 		deStr = JSON.parse(mi);
				// 	} catch (error) {

				// 		deStr = mi; // 或者其他默认值
				// 	}
				// 	dataJson.data = deStr
				// 	const data = {
				// 		data: JSON.stringify(dataJson)
				// 	}
				// 	resolve(data);

				// }
				const response = JSON.parse(res.data);
				console.log(66666666)
				console.log(response)
				resolve(response)
			},
			fail: (res) => {
				reject(res)
			}
		})
	})
}
export function downloadFile(url) {
	return new Promise((resolve, reject) => {
		uni.downloadFile({
			url,
			success: (res) => {
				resolve(res)
			},
			fail: (res) => {
				reject(res)
			}
		})
	})
}